/**
 * Copyright (c) 2005-2012 https://github.com/zhangkaitao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.sishuok.hello;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Component;

/** http://jinnianshilongnian.iteye.com/blog/1902886
 * 3、定义有序监听器
 * 实现SmartApplicationListener接口即可。
 *
 * supportsEventType：用于指定支持的事件类型，只有支持的才调用onApplicationEvent；
 * supportsSourceType：支持的目标类型，只有支持的才调用onApplicationEvent；
 * getOrder：即顺序，越小优先级越高
 *
 * <p>User: Zhang Kaitao
 * <p>Date: 13-7-8 下午9:14
 * <p>Version: 1.0
 */
@Component
public class SunliuListener implements SmartApplicationListener {

    @Override
    public boolean supportsEventType(final Class<? extends ApplicationEvent> eventType) {
        return eventType == ContentEvent.class;
    }

    @Override
    public boolean supportsSourceType(final Class<?> sourceType) {
        return sourceType == String.class;
    }

    @Override
    public void onApplicationEvent(final ApplicationEvent event) {
        System.out.println("孙六在王五之后收到新的内容：" + event.getSource());
    }

    @Override
    public int getOrder() {
        return 2;
    }
}
